# Build recipe for iana-etc.
#
# Copyright (c) 2017, 2021-2022 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=iana-etc
version=2.30
update_version=20211229
arch=noarch
release=1

# Define a category for the output of the package name
pkgcategory=data

# Define custom package version
pkgversion=${version}_${update_version}

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch="
  http://sethwklein.net/$tarname
  https://github.com/Mic92/iana-etc/releases/download/${version}/$tarname
"

description="
Provides /etc/services and /etc/protocols files.

The iana-etc package provides the Unix/Linux /etc/services and
/etc/protocols files.  Using data from the Internet Assigned
Numbers Authority <https://www.iana.org>.
"

homepage=https://www.iana.org/protocols
license=OSLv3.0

# Source documentation
docs="COPYING CREDITS NEWS README VERSION"
docsdir="${docdir}/${program}-${pkgversion}"

build()
{
    unpack "${tardir}/$tarname"
    unpack "${tardir}/${program}-${update_version}.tar.gz"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    make all && make DESTDIR="$destdir" install

    # Update files from 'update_version' iana's variant
    cp -f -p "${TMPDIR}/${program}-${update_version}"/protocols \
     "${destdir}/etc"
    cp -f -p "${TMPDIR}/${program}-${update_version}"/services \
     "${destdir}/etc"

    # To handle config file(s)
    touch "${destdir}/etc/.graft-config"

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"

    # Do not keep the update version source, unless --keep is passed in Qi
    if test -z "$keep_srcdir"
    then
        rm -rf -- "${TMPDIR}/${program}-${update_version}"
    fi
    unset -v update_version
}

